package com.example.demo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.bean.VoiceConfig;
import com.example.demo.service.VoiceConfigService;
import com.example.demo.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/voice")
@RequiredArgsConstructor
public class VoiceConfigController {


    private final VoiceConfigService service;

    @GetMapping("/dropdown")
    public Result<List<VoiceConfig>> dropdown() {
        return Result.success(service.list());
    }

    @GetMapping("/page")
    public Result<IPage<VoiceConfig>> page(@RequestParam(defaultValue = "1") long current,
                                           @RequestParam(defaultValue = "10") long size) {
        IPage<VoiceConfig> p = new Page<>(current, size);
        return Result.success(service.page(p));
    }

    @GetMapping("/{id}")
    public Result<VoiceConfig> get(@PathVariable Integer id) {
        return Result.success(service.getById(id));
    }

    @PostMapping
    public Result<Void> save(@RequestBody VoiceConfig dto) {
        service.save(dto);
        return Result.success(null);
    }

    @PutMapping
    public Result<Void> update(@RequestBody VoiceConfig dto) {
        service.update(dto);
        return Result.success(null);
    }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Integer id) {
        service.deleteById(id);
        return Result.success(null);
    }

    @PostMapping("/default/{id}")
    public Result<Void> setDefault(@PathVariable Integer id) {
        service.setDefault(id);
        return Result.success(null);
    }
}
